package com.mindao.app.weixin.conf;

import com.jfinal.weixin.sdk.api.ApiConfig;
import com.jfinal.weixin.sdk.api.ApiConfigKit;
import com.tencent.common.Configure;

/**
/* 版权所有： 广州敏道科技有限公司
/*
/* 功能描述：企业软文发布渠道，目前仅支持微信
/*
/* 创 建 人：李国才
/* 创建时间：2016年6月13日 下午4:31:54 	
 **/
 
public class WxmpAccount  { 
 
//	
	public final static Integer WXTYPE_READ=1;
	public final static Integer WXTYPE_READ_AUTH=2;
	public final static Integer WXTYPE_SERVICE=3;
	public final static Integer WXTYPE_SERVICE_AUTH=4;
	public final static Integer WXTYPE_ENTERPRISE=5;
	public final static Integer WXTYPE_ENTERPRISE_AUTH=6;
 
	
	private Long id=1L;
	private String uuid="198340238505";
	
	private String name;
 
	/**
	 * 微信公众号配置相关字段
	 */
	private String wxToken = null;
	private String wxAppId = null;
	private String wxAppSecret = null;
	private String wxEncodingAesKey = null;
	private Boolean wxMessageEncrypt = false;	// 消息加密与否
	
	//支付相关
	private String mchID = null;
	private String subMchID=null;
	private String ip = null;
	private String payKey = null;
	private String certLocalPath=null;
	private String certPassword=null;
//	//商家名称
//	private String mchName = null;
 	
	//微信号类型
	private Integer wxType=WXTYPE_SERVICE_AUTH;
	//服务器地址和上下文配置
	private String serverContext;
	/**
	 * 进行鉴权的部分url
	 */
	private String serverAuthURI ;
	/**
	 * 是否读配置文件得到配置
	 */
	private Boolean configFileFlag;
 
	public String getWxToken() {
		return wxToken;
	}

	public void setWxToken(String wxToken) {
		this.wxToken = wxToken;
	}

	public String getWxAppId() {
		return wxAppId;
	}

	public void setWxAppId(String wxAppId) {
		this.wxAppId = wxAppId;
	}

	public String getWxAppSecret() {
		return wxAppSecret;
	}

	public void setWxAppSecret(String wxAppSecret) {
		this.wxAppSecret = wxAppSecret;
	}

	public String getWxEncodingAesKey() {
		return wxEncodingAesKey;
	}

	public void setWxEncodingAesKey(String wxEncodingAesKey) {
		this.wxEncodingAesKey = wxEncodingAesKey;
	}

	public Boolean getWxMessageEncrypt() {
		return wxMessageEncrypt;
	}

	public void setWxMessageEncrypt(Boolean wxMessageEncrypt) {
		this.wxMessageEncrypt = wxMessageEncrypt;
	}
	
 

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public WxmpAccount(){
		
	}
	public WxmpAccount(String name,String token, String appId, String appSecret, boolean messageEncrypt, String encodingAesKey) {
		setName(name);
		setWxToken(token);
		setWxAppId(appId);
		setWxAppSecret(appSecret);
		setWxMessageEncrypt(messageEncrypt);
		setWxEncodingAesKey(encodingAesKey);
	}

	public String getMchID() {
		return mchID;
	}

	public void setMchID(String mchID) {
		this.mchID = mchID;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getPayKey() {
		return payKey;
	}

	public void setPayKey(String payKey) {
		this.payKey = payKey;
	}

	public Integer getWxType() {
		return wxType;
	}

	public void setWxType(Integer wxType) {
		this.wxType = wxType;
	}

	public String getServerContext() {
		return serverContext;
	}

	public void setServerContext(String serverContext) {
		this.serverContext = serverContext;
	}

	public String getServerAuthURI() {
		return serverAuthURI;
	}

	public void setServerAuthURI(String serverAuthURI) {
		this.serverAuthURI = serverAuthURI;
	}

 
	
	
	public void init(){
        //更新微信支付的Configure的配置
		Configure.setAppID(this.getWxAppId());
		Configure.setMchID(this.getMchID());
		Configure.setKey(this.getPayKey());
		Configure.setIp(this.getIp());
        Configure.setSubMchID(this.getSubMchID());
        Configure.setCertLocalPath(this.getCertLocalPath());
        Configure.setCertPassword(this.getCertPassword());
        Configure.setMchName(name);
		
		//更新微信公众号的配置
		ApiConfig apiConfig=new ApiConfig(getWxToken(), getWxAppId(), getWxAppSecret(), getWxMessageEncrypt(), getWxEncodingAesKey()==null?"":getWxEncodingAesKey(),getServerContext(),getServerAuthURI());
		apiConfig.setIp(getIp());
		apiConfig.setPayKey(getPayKey());
		//ApiConfigKit kit=(ApiConfigKit)EaCommonUtils.getBean("apiConfigKit");
		ApiConfigKit.setConfigFileFlag(configFileFlag);
		ApiConfigKit.setApiConfig(apiConfig);
		 
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public Boolean getConfigFileFlag() {
		return configFileFlag;
	}

	public void setConfigFileFlag(Boolean configFileFlag) {
		this.configFileFlag = configFileFlag;
	}

	public String getSubMchID() {
		return subMchID;
	}

	public void setSubMchID(String subMchID) {
		this.subMchID = subMchID;
	}

	public String getCertLocalPath() {
		return certLocalPath;
	}

	public void setCertLocalPath(String certLocalPath) {
		this.certLocalPath = certLocalPath;
	}

	public String getCertPassword() {
		return certPassword;
	}

	public void setCertPassword(String certPassword) {
		this.certPassword = certPassword;
	}

 
    
}
